package com.fzfnn.scrapbook.controller;

import com.fzfnn.scrapbook.service.MessageService;
import com.fzfnn.scrapbook.service.UserService;
import com.fzfnn.scrapbook.util.R;
import com.fzfnn.scrapbook.vo.MessageVo;
import com.fzfnn.scrapbook.vo.PrivateChatUserDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/chat")
@Tag(name = "聊天接口", description = "聊天相关接口")

public class ChatController {
    @Autowired
    private MessageService messageService;
    @Autowired
    private UserService userService;

    @GetMapping("/private-list")
    @Operation(summary = "获取用户私聊列表&最后一条消息")
    public R getPrivateChatList(@RequestHeader("Authorization")String token) {
        return R.successData(messageService.getPrivateChatList(token));
    }
    @GetMapping("/history")
    @Operation(summary = "获取用户与指定用户的聊天记录")
    public R getHistoryMessages(@RequestHeader("Authorization")String token,
                                                 @RequestParam Long receiverId) {
        return R.successData( messageService.getHistoryMessages(token, receiverId));
    }
    @GetMapping("/private-users")
    @Operation(summary = "获取用户私聊用户的名字和头像")
    public R getPrivateChatUsers(@RequestHeader("Authorization")String token,Long receiverId) {
        return R.successData(userService.getPrivateChatUsers(token, receiverId));
    }
    @DeleteMapping("/chat/{receiverId}")
    @Operation(summary = "删除用户与指定用户的聊天记录")
    public R deleteChatHistory(@RequestHeader("Authorization") String token,
                               @PathVariable Long receiverId) {
        return messageService.deleteChatHistory(token, receiverId);
    }

}
